package com.hobee.basic.config.rabbit;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;

/**
 * @author junjie.li
 * @date 2020/7/21 15:37
 */
@Configuration
public class MQConfig {

    protected static final ArrayList<String> QUEUE_NAMES= new ArrayList<>();

    protected static final String QUEUE_NICELOO_BOOT = "nicelooBoot";

    private static final String TOPIC_NICELOO = "niceloo";

    @Bean(value = "nicelooBoot")
    public Queue nicelooBoot() {
        Queue nicelooBoot = new Queue(QUEUE_NICELOO_BOOT, true, false, false);
        QUEUE_NAMES.add(nicelooBoot.getName());
        return nicelooBoot;
    }

    @Bean
    public TopicExchange topicExchange() {
        return new TopicExchange(TOPIC_NICELOO, true, false);
    }

    @Bean
    public Binding binding(@Qualifier("nicelooBoot") Queue queue, TopicExchange topicExchange) {
        return BindingBuilder.bind(queue).to(topicExchange).with("nicelooBoot.#");
    }
}
